package xing.infrastructure.data;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class CallResult {

    public CallResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static CallResult ok() {
        return new CallResult(200,null,null);
    }

    public static CallResult ok(Object data) {
        return new CallResult(200,null,data);
    }

    public static CallResult error(String msg) {
        return new CallResult(-1,msg,null);
    }
    public static CallResult error(String msg,Object data) {
        return new CallResult(-1,msg,data);
    }

    public static CallResult code(int code) {
        return new CallResult(code,null,null);
    }
    @JsonIgnore
    public Boolean isSuccess() {return this.code>0;}

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    // 响应业务状态
    private Integer code;

    // 响应消息
    private String msg;

    // 响应中的数据
    private Object data;
}
